<?php

/**
 * This is the model class for table "mcrjo_coffeeproduct".
 *
 * The followings are the available columns in table 'mcrjo_coffeeproduct':
 * @property integer $id
 * @property integer $shopId
 * @property integer $coffeeType
 * @property integer $size
 * @property integer $milk
 * @property integer $price
 */
class CoffeeProduct extends CActiveRecord
{
	public static function coffee_types($key=null){
		$options= array(
		//1=>'Espresso',
		//2=>'Double Espresso',
		3=>'Long Black',
		4=>'Flat White',
		5=>'Long Macchiato',
		6=>'Mocha',
		7=>'Cappuccino',
		8=>'Latte',
		9=>'Piccolo',
		10=>'Short Black',
		11=>'Short Macchiato',
		
		);
		$key=strval($key);
		if($key!==null&&isset($options[$key])){
			return $options[$key];
		}
		return $options;
	}

	public static function coffee_sizes($key=null){
		$options=array(
		1=>'Small',
		2=>'Medium',
		3=>'Large'
		);
		$key=strval($key);
		if($key!==null&&isset($options[$key])){
			return $options[$key];
		}
		return $options;
	}

	public static function coffee_milks($key=null){
		$options=array(
		1=>'None',
		2=>'Full Cream',
		3=>'Skim',
		4=>'Soy'
		);
		$key=strval($key);
		if($key!==null&&isset($options[$key])){
			return $options[$key];
		}
		return $options;
	}

	public static function coffee_sugar_types($key=null){
		$options=array(
		1=>'Raw',
		2=>'S & L',
		3=>'Brown',
		4=>'White'
		);
		$key=strval($key);
		if($key!==null&&isset($options[$key])){
			return $options[$key];
		}
		return $options;
	}
	public static function coffee_sugar_nums($key=null){
		$options=array(
		0=>'0',
		1=>'1',
		2=>'2',
		3=>'3',
		4=>'4'
		);
		$key=strval($key);
		if($key!==null&&isset($options[$key])){
			return $options[$key];
		}
		return $options;
	}

	public static function available_shops(){
		$availableCoffeeShops=array();
		$dbPos=Pos::model()->with('shop')->together()->findAll();
		foreach ($dbPos as $pos){
			$dbShop=$pos->shop;
			$availableCoffeeShops[$dbShop->id]=$dbShop->name.' - '.$dbShop->suburb.' '.$dbShop->state;
		}
		return $availableCoffeeShops;
	}

	/**
	 * Returns the static model of the specified AR class.
	 * @return CoffeeProduct the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'mcrjo_coffeeproduct';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
		array('shopId, coffeeType, size, milk, price', 'required'),
		array('shopId, coffeeType, size, milk, price', 'numerical', 'integerOnly'=>true),
		// The following rule is used by search().
		// Please remove those attributes that should not be searched.
		array('id, shopId, coffeeType, size, milk, price', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'shop' => array(self::BELONGS_TO, 'CoffeeShop', 'shopId'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'shopId' => 'Shop',
			'coffeeType' => 'Coffee Type',
			'size' => 'Size',
			'milk' => 'Milk',
			'price' => 'Price',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);

		$criteria->compare('shopId',$this->shopId);

		$criteria->compare('coffeeType',$this->coffeeType);

		$criteria->compare('size',$this->size);

		$criteria->compare('milk',$this->milk);

		$criteria->compare('price',$this->price);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}